package com.atguigu.gulimall.product.entity;

import com.atguigu.common.valid.AddGroup;
import com.atguigu.common.valid.ListValue;
import com.atguigu.common.valid.UpdateGroup;
import com.atguigu.common.valid.UpdateStatusGroup;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import org.hibernate.validator.constraints.URL;

import javax.validation.constraints.*;
import java.io.Serializable;


@Data
@TableName("pms_brand")
public class BrandEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * Long类型，所以不能用@NotEmpty
     * groups是common模块下valid包中的空接口，给分组校验使用的
     */
    @NotNull(message = "修改必须指定品牌id", groups = {UpdateGroup.class})
    @Null(message = "新增不能指定id", groups = {AddGroup.class})
    @TableId
    private Long brandId;
    /**
     * 品牌名
     * 无论新增和修改都要提交，所以这两个分组都要
     */
    @NotBlank(message = "品牌名不能为空或空字符!!!!!", groups = {UpdateGroup.class, AddGroup.class})
    private String name;
    /**
     * 品牌logo地址
     */
    @NotEmpty
    @URL(message = "logo必须是一个合法的url地址", groups = {UpdateGroup.class, AddGroup.class})
    private String logo;
    /**
     *
     */
    private String descript;
    /**
     *
     */
    @NotNull(groups = {AddGroup.class,UpdateStatusGroup.class})
    @ListValue(vals = {0, 1}, groups = {AddGroup.class,UpdateStatusGroup.class})
    private Integer showStatus;
    /**
     * @Pattern 是自定义校验规则，要求你传递的参数必须符合我们的内容，支持正则
     */
    @NotEmpty
    @Pattern(regexp = "^[a-zA-Z]$", message = "检索首字母必须是一个字母", groups = {AddGroup.class})
    private String firstLetter;
    /**
     * @Min 他是Integer，因此不能使用NotEmpty，只能使用NotNull
     */
    @NotNull
    @Min(value = 0, message = "排序必须大于等于0", groups = {AddGroup.class})
    private Integer sort;

}
